feat: disable node-sensitive endpoints during shutdown#2030
feat: disable node-sensitive endpoints during shutdown#2030Dunsin-cyber wants to merge 3 commits intogetAlby:masterfrom
Conversation
📝 WalkthroughWalkthroughAdds a shutdown flag to the service, exposes IsShuttingDown via API and Wails, introduces ShutdownMiddleware used by HTTP/Wails to return 503 for most endpoints during shutdown while allowing health/safe routes and Changes
Sequence DiagramsequenceDiagram
participant Client
participant Handler as HTTP/Wails Handler
participant ShutdownMW as Shutdown Middleware
participant Service as Service (IsShuttingDown)
participant Endpoint as Endpoint Handler
Client->>Handler: Request (e.g., /api/peers)
Handler->>ShutdownMW: pass request
ShutdownMW->>Service: IsShuttingDown()?
Service-->>ShutdownMW: true
ShutdownMW-->>Client: 503 Service Unavailable ("Node is shutting down")
Client->>Handler: Request (e.g., /api/health)
Handler->>ShutdownMW: pass request
ShutdownMW->>Endpoint: allowed (safe route)
Endpoint-->>Client: 200 OK
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@http/http_service_test.go`:
- Around line 396-535: Remove the redundant
e.Use(middleware.ShutdownMiddleware(mockSvc)) calls from
TestShutdown_BlockedEndpoint and TestShutdown_AllowedEndpoint since
RegisterSharedRoutes already wires ShutdownMiddleware; keep all other setup
unchanged. In TestShutdown_AllowedEndpoint change the final assertion to
explicitly expect http.StatusOK for the GET /api/node/status response (use the
existing rec2 and request), replacing the current assert.NotEqual that checks
against 503. Ensure references are to ShutdownMiddleware, RegisterSharedRoutes,
TestShutdown_BlockedEndpoint, and TestShutdown_AllowedEndpoint so the changes
are made in the correct tests.
In `@wails/wails_handlers.go`:
- Around line 27-42: The router currently checks raw route strings against
safeRoutes in WailsRequestRouter which fails when query strings are present;
normalize the incoming route before the safeRoutes lookup by extracting just the
path (e.g., strip anything after '?' or use URL parsing) so the existing
safeRoutes map and the strings.HasPrefix(route, "/api/alby/") check operate on
the path-only value, then use that normalized path in isSafe and subsequent
logic (references: WailsRequestRouter, safeRoutes, isSafe, CheckShutdown).
🧹 Nitpick comments (1)
http/http_service.go (1)
93-96: Ensure shutdown 503s still carry a Request ID.
ShutdownMiddlewareshort-circuits beforeRequestID, so shutdown responses won’t get a request ID (and logs may miss it). Consider registeringRequestIDbefore the shutdown guard. Please confirm the intended Echo middleware order per v4 docs.Suggested reorder
- e.Use(middleware.ShutdownMiddleware(httpSvc.api)) - - e.Use(echoMiddleware.Recover()) - e.Use(echoMiddleware.RequestID()) + e.Use(echoMiddleware.RequestID()) + e.Use(middleware.ShutdownMiddleware(httpSvc.api)) + + e.Use(echoMiddleware.Recover())
fixes #2018
Implemented a
ShutdownMiddlewareand updated theWailsRequestRouterto block node-related requests when the node is shutting down.Summary by CodeRabbit
New Features
Tests